<?php

declare (strict_types=1);
namespace Swb\Shop\Model;

use Hyperf\Cache\Annotation\Cacheable;
use Hyperf\DbConnection\Db;
use Hyperf\DbConnection\Model\Model as BaseModel;
/**
 * @property int $id 
 * @property int $group_id 
 * @property string $code 
 * @property string $name 
 * @property string $icon_id 
 * @property string $use_value 
 * @property string $create_by 
 * @property string $update_by 
 * @property string $create_time 
 * @property string $update_time 
 * @property int $del_flag 
 */
class SysDataDict extends BaseModel
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'sys_data_dict';
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [];
    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = ['id' => 'int', 'group_id' => 'integer', 'del_flag' => 'integer'];

    /**
     * @param $code
     * @param string $field
     * @return \Hyperf\Database\Model\Builder[]|\Hyperf\Database\Model\Collection
     * User : 码农先生
     * Email: 807098383@qq.com
     * Website: http://blog.zsboss888.com
     * 获取分类 205
     */
    public function getAllDict($code,$field='*')
    {
        return self::query()->where('code',$code)
            ->where('del_flag',1)
            ->select($field)->get();
    }
	public function getByCodeDict($code,$field='*')
	{
		return Db::table('sys_data_dict_group')->where('code',$code)
			->where('del_flag',1)
			->select($field)->first();
	}
    public function getFieldByGroupId($group_id,$field='*')
    {
        return self::query()->where('group_id',$group_id)
            ->where('del_flag',1)
            ->select($field)->get();
    }
    public function getFieldByUseValue($id,$code)
    {
        return self::query()->where('use_value',$id)
            ->where('code',$code)
            ->value('name');
    }
	public function getFieldByUseGroupValue($id,$group_id)
	{
		return self::query()->where('use_value',$id)
			->where('group_id',$group_id)
			->value('name');
	}
    public function getFieldById($id)
    {
        return self::query()->where('id',$id)
            ->value('name');
    }

	/**
	 * @Cacheable(prefix="dict_area")
	 * @return array
	 * User : 码农先生
	 * Email: 807098383@qq.com
	 * Website: http://blog.zsboss888.com
	 *
	 */
	public function get_dict_area()
	{
		return self::query()->select('name', 'use_value')->where('group_id', 53)->where('del_flag', 1)->get()->toArray();

	}

	public function getByIdSearchName($ids)
	{
		return self::query()->whereIn('id',$ids)->pluck('name')->toArray();
	}
}